home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Screenblankers / XSB / xsb.c < prev    next >
C/C++ Source or Header  |  1996-09-26  |  6KB  |  245 lines

  1. #include "xsb.h"
  2. #include "startup.h"
  3.  
  4. extern void popup(void);
  5. extern void loadprefs(void);
  6.  
  7. /* hotkey */
  8. char hotkey[40]={"alt shift del"};
  9. char popkey[40]={"alt shift help"};
  10. char xsbname[40]={"xsbstandard.library"};
  11. long tick; /* 5 sec tick count */
  12. long prio;
  13.  
  14. extern long blankmouse,mousetimeout,screentimeout,randomblanker;
  15.  
  16. #define CreatePort alsosoeinmist
  17. #include <clib/alib_protos.h>
  18.  
  19. struct Library *IconBase,*CxBase,*XSBBase,*GfxBase;
  20. struct IntuitionBase *IntuitionBase;
  21. struct GadToolsBase *GadToolsBase;
  22. struct MsgPort *mp;
  23. CxObj *filter1,*filter2,*comms,*broker,*cxsig1,*cxsig2;
  24. struct TextAttr top80={"topaz.font",8,0,0};
  25.  
  26. char version[]={"$VER: XSBCX V1.0 (" __DATE__ " " __TIME__ ")"};
  27.  
  28. struct InputXpression fix1={IX_VERSION,IECLASS_RAWKEY,0,0,0,0,0};
  29. struct InputXpression fix2={IX_VERSION,IECLASS_RAWMOUSE,0,0,0,0,0};
  30.  
  31. struct timerequest treq;
  32. struct MsgPort *timerport;
  33. int timeropen;
  34.  
  35. void cxcleanup(char *error)
  36. {
  37.  if(broker) DeleteCxObjAll(broker);
  38.  if(IconBase) CloseLibrary(IconBase);
  39.  if(CxBase) CloseLibrary(CxBase);
  40.  if(IntuitionBase) CloseLibrary(IntuitionBase);
  41.  if(GfxBase) CloseLibrary(GfxBase);
  42.  if(GadToolsBase) CloseLibrary(GadToolsBase);
  43.  if(mp) DeleteMsgPort(mp);
  44.  if(timeropen) {
  45.     AbortIO(&treq);
  46.     WaitIO(&treq);
  47.     CloseDevice(&treq);
  48.  }
  49.  if(timerport) DeleteMsgPort(timerport);
  50.  if(error) VPrintf("XSBCX: %s\n",&error);
  51.  exit((error)?20:0);
  52. }
  53.  
  54. #define BUFF(sg) ((struct StringInfo*)sg->SpecialInfo)->Buffer
  55.  
  56. long mouseoff;
  57. extern struct Custom __far custom;
  58. void offmouse(void)
  59. {
  60.     custom.dmacon=1<<5;
  61.     mouseoff++;
  62. }
  63.  
  64. void onmouse(void)
  65. {
  66.     custom.dmacon=(1<<15)|(1<<5);
  67.     mouseoff=0;
  68. }
  69.  
  70. static struct XSBInfo xsbi;
  71. static struct XSBPref xsp[10];
  72. void doblank(char *name)
  73. {
  74.     BPTR f;
  75.     char prefname[30],preffile[40],*p;
  76.     struct XSBPref *prp=0;
  77.  
  78.     if(!(XSBBase=OldOpenLibrary(name))) {
  79.         doreq("XSBCX","Unable to open blanker library\n%s","Cancel",xsbname);
  80.         return;
  81.     }
  82.     strcpy(p=prefname,&name[3]);
  83.     while(*p!='.') p++; *p=0;
  84.     sprintf(preffile,"ENV:XSB/%s.XSBP",prefname);
  85.     if(f=Open(preffile,MODE_OLDFILE)) {
  86.         Read(f,prp=xsp,400);
  87.         Close(f);
  88.     }
  89.     offmouse();
  90.     SetSignal(0,SIGBREAKF_CTRL_D);
  91.     xsbi.tr=&treq;
  92.     xsbi.prefs=prp;
  93.     XSBBlankScreen(SIGBREAKF_CTRL_D,&xsbi);
  94.     CloseLibrary(XSBBase);
  95.     onmouse();
  96. }
  97.  
  98. void brokeron(void)
  99. {
  100.          ActivateCxObj(broker,-1);
  101. }
  102.  
  103. void brokeroff(void)
  104. {
  105.          ActivateCxObj(broker,0);
  106. }
  107.  
  108. void qtimer(void)
  109. {
  110.  treq.tr_node.io_Command=TR_ADDREQUEST;
  111.  treq.tr_time.tv_secs=5;
  112.  treq.tr_time.tv_micro=0;
  113.  BeginIO(&treq);
  114. }
  115.  
  116. void atimer(void)
  117. {
  118.  AbortIO(&treq);
  119.  WaitIO(&treq);
  120.  SetSignal(0,1<<(timerport->mp_SigBit));
  121. }
  122.  
  123. void main(int argc,char **argv)
  124. {
  125.  char **tt;
  126.  CxMsg *msg;
  127.  struct NewBroker nb;
  128.  long sigmask=0;
  129.  long id;
  130.  int dopopup=0;
  131.  
  132.  if(argc==2 && *argv[1]=='?') {
  133.    PutStr("\nUsage: XSBCX [CX_PRIORITY=pri] [CX_POPUP=YES|NO]\n\n");
  134.    exit(0);
  135.  }
  136.  
  137.  if(!(IconBase=OpenLibrary("icon.library",37)))
  138.    cxcleanup("can't open icon.library");
  139.  if(!(CxBase=OpenLibrary("commodities.library",37)))
  140.    cxcleanup("can't open commodities.library");
  141.  IntuitionBase=OpenLibrary("intuition.library",37);
  142.  GadToolsBase=OpenLibrary("gadtools.library",37);
  143.  GfxBase=OldOpenLibrary("graphics.library");
  144.  
  145.  loadprefs();
  146.  if(argc!=1) {
  147.    if(!(tt=ArgArrayInit(argc,argv))) cxcleanup("arg error");
  148.    prio=ArgInt(tt,"CX_PRIORITY",0);
  149.    dopopup=!stricmp("yes",ArgString(tt,"CX_POPUP","no"));
  150.    ArgArrayDone();
  151.  }
  152.  if(!(mp=CreateMsgPort()))
  153.    cxcleanup("out of memory");
  154.  
  155.  filter1=CxFilter(hotkey);
  156.  AttachCxObj(filter1,CxSignal(FindTask(0),SIGBREAKB_CTRL_E));
  157.  AttachCxObj(filter1,CxTranslate(0));
  158.  
  159.  filter2=CxFilter(popkey);
  160.  AttachCxObj(filter2,CxSignal(FindTask(0),SIGBREAKB_CTRL_F));
  161.  AttachCxObj(filter2,CxTranslate(0));
  162.  
  163.  cxsig1=CxFilter("alt shift del");
  164.  AttachCxObj(cxsig1,CxSignal(FindTask(0),SIGBREAKB_CTRL_D));
  165.  cxsig2=CxFilter("alt shift del");
  166.  AttachCxObj(cxsig2,CxSignal(FindTask(0),SIGBREAKB_CTRL_D));
  167.  SetFilterIX(cxsig1,&fix1);
  168.  SetFilterIX(cxsig2,&fix2);
  169.  
  170.  nb.nb_Version=NB_VERSION;
  171.  nb.nb_Name="XSBCX";
  172.  nb.nb_Title="eXternal Screen Blanker Commodity";
  173.  nb.nb_Descr="Driver for XSB libraries";
  174.  nb.nb_Unique=NBU_UNIQUE|NBU_NOTIFY;
  175.  nb.nb_Pri=prio;
  176.  nb.nb_Flags=COF_SHOW_HIDE;
  177.  nb.nb_Port=mp;
  178.  nb.nb_ReservedChannel=0;
  179.  
  180.  if(!(broker=CxBroker(&nb,0)))
  181.    cxcleanup(0);
  182.  
  183.  AttachCxObj(broker,filter1);
  184.  AttachCxObj(broker,filter2);
  185.  AttachCxObj(broker,cxsig1);
  186.  AttachCxObj(broker,cxsig2);
  187.  
  188.  timerport=CreateMsgPort();
  189.  treq.tr_node.io_Message.mn_ReplyPort=timerport;
  190.  OpenDevice("timer.device",UNIT_VBLANK,&treq,0);
  191.  timeropen=1;
  192.  qtimer();
  193.  
  194.  brokeron();
  195.  
  196.  for(;;) {
  197.    if(!dopopup) sigmask=Wait((1<<timerport->mp_SigBit)|(1<<mp->mp_SigBit)|SIGBREAKF_CTRL_E|SIGBREAKF_CTRL_F|SIGBREAKF_CTRL_C|SIGBREAKF_CTRL_D);
  198.    if(sigmask&SIGBREAKF_CTRL_C) {
  199.      cxcleanup(0);
  200.    }
  201.    if(sigmask&SIGBREAKF_CTRL_D) {
  202.     tick=0;
  203.     if(mouseoff) onmouse();
  204.    }
  205.    if(sigmask&SIGBREAKF_CTRL_E) {
  206.     atimer();
  207.     Delay(10);
  208.     Wait(SIGBREAKF_CTRL_D);
  209.     doblank(xsbname);
  210.     qtimer();
  211.    }
  212.    if(sigmask&SIGBREAKF_CTRL_F || dopopup) {
  213.      brokeroff(); atimer(); popup(); qtimer(); brokeron(); dopopup=0;
  214.     SetFilter(filter1,hotkey);
  215.     SetFilter(filter2,popkey);
  216.    }
  217.    if(sigmask&(1<<timerport->mp_SigBit)) {
  218. /*    DisplayBeep(0);*/
  219.     WaitIO(&treq);
  220.     tick++;
  221.     if(blankmouse && tick>mousetimeout && !mouseoff) offmouse();
  222.     if(tick>screentimeout) { doblank(xsbname); tick=0; }
  223.     qtimer();
  224.    }
  225.  
  226.    if(sigmask&(1<<mp->mp_SigBit)) {
  227.      if(msg=GetMsg(mp)) {
  228.        id=CxMsgID(msg);
  229.        ReplyMsg(msg);
  230.        switch(id) {
  231.          case CXCMD_DISABLE: brokeroff(); break;
  232.          case CXCMD_ENABLE: brokeron(); break;
  233.          case CXCMD_UNIQUE: /* fallthrough */
  234.          case CXCMD_APPEAR: 
  235.          brokeroff(); atimer(); popup(); qtimer(); brokeron();
  236.         SetFilter(filter1,hotkey);
  237.         SetFilter(filter2,popkey);
  238.          break;
  239.          case CXCMD_KILL: cxcleanup(0); break;
  240.        }
  241.      }
  242.    }
  243.  }
  244. }
  245.